<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- jQuery -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />  
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<!-- 달력 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/FullCalendar/jquery.ui.datepicker-ko.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/intranet/counsel/list.css"/>
<script type="text/javascript">

	$(window).on('load', function () {
	
		$( ".cl_select" ).selectpicker({
			style: 'btn-info'
		});
		$( ".cl_select2" ).selectpicker({
			style: 'btn-info'
		});
		$("#fullFind").hide();
		
		if("${sessionScope.c_sa_search}" == "sa_no"){
			$("#sa_search").selectpicker('val',"${sessionScope.c_sa_search}");
			document.getElementById("sa_find").value = "${sessionScope.c_sa_no}";
		}else if("${sessionScope.c_sa_search}" == "sa_nm"){
			$("#sa_search").selectpicker('val',"${sessionScope.c_sa_search}");
			document.getElementById("sa_find").value = "${sessionScope.c_sa_nm}";
		}
		if("${sessionScope.c_pd_search}" == "pd_no"){
			$("#pd_search").selectpicker('val',"${sessionScope.c_pd_search}");
			document.getElementById("pd_find").value = "${sessionScope.c_pd_no}";
		}else if("${sessionScope.c_pd_search}" == "pd_nm"){
			$("#pd_search").selectpicker('val',"${sessionScope.c_pd_search}");
			document.getElementById("pd_find").value = "${sessionScope.c_pd_nm}";
		}
		if("${sessionScope.c_cs_search}" == "cs_no"){
			$("#cs_search").selectpicker('val',"${sessionScope.c_cs_search}");
			document.getElementById("cs_find").value = "${sessionScope.c_cs_no}";
		}else if("${sessionScope.c_cs_search}" == "rg_pp"){
			$("#cs_search").selectpicker('val',"${sessionScope.c_cs_search}");
			document.getElementById("cs_find").value = "${sessionScope.c_rg_pp}";
		}
		if("${sessionScope.c_sa_dpm}" != ""){
			$("#sa_dpm").selectpicker('val',"${sessionScope.c_sa_dpm}");
		}
		if("${sessionScope.c_sa_gd}" != ""){
			$("#sa_gd").selectpicker('val',"${sessionScope.c_sa_gd}");
		}
		if("${sessionScope.c_cs_loan}" != ""){
			$("#cs_loan").selectpicker('val',"${sessionScope.c_cs_loan}");
		}
		if("${sessionScope.c_cs_sd}" != ""){
			document.getElementById("cs_sd").value = "${sessionScope.c_cs_sd}"; 
			document.getElementById("cs_ed").value = "${sessionScope.c_cs_ed}";	
		}
		if("${sessionScope.c_ct_ing}" != ""){
			$("#ct_ing").selectpicker('val',"${sessionScope.c_ct_ing}");
		}
		//기본 목록 불러오기
		$.ajax({
			url : '${pageContext.request.contextPath}/Coun/CounList.clamp',
			type : 'POST',
			cache : false,
			data : 'full=no',
			success: function(html){
				$("#coun_list").html(html);
			}
		});
		fnSED();
	});

	var findFlag=false;//상세검색 열렸는지 안열렸는지
	//상세검색 클릭시 사용
	function fnFullFind() {
		var ff = document.getElementById("btn1");
		$("#fullFind").slideToggle("slow");
		if(findFlag!=false){
			findFlag=false;
			ff.style.backgroundColor="#d9534f";
			ff.style.borderColor="#ac2925";
		}else{
			findFlag=true;
			ff.style.backgroundColor="#000000";
			ff.style.borderColor="#ffffff";
		}
	}
	
	//상담 상세페이지 이동시 사용
	function fnCounEdit(no) {
		var frm = document.getElementById("view");
		document.getElementById("cs_no").value = no;
		frm.action = "${pageContext.request.contextPath}/Coun/CounView.clamp"
		frm.submit();
		//location.href="${pageContext.request.contextPath}/Coun/CounView.clamp?cs_no="+no;
	}
	//달력
	function fnSED(){
		$("#cs_sd").datepicker({
			buttonImageOnly: true, //이미지만 보이기
			changeMonth: true,
			changeYear: true,
			autoSize: true,
			onClose: function( selectedDate ) {
			        $( "#cs_ed" ).datepicker( "option", "minDate", selectedDate );
			}
		});
		$("#cs_sd").css("width","110px");
		$("#cs_ed").datepicker({
			buttonImageOnly: true, //이미지만 보이기
			changeMonth: true,
			changeYear: true,
			autoSize: true,
			onClose: function( selectedDate ) {
		        $( "#cs_sd" ).datepicker( "option", "maxDate", selectedDate );
			}
		});
		$("#cs_ed").css("width","110px");
	}
	
	//상담일 검색 값 변환시 사용
	function fnCD(d) {
		var sd = document.getElementById("cs_sd").value;
		var ed = document.getElementById("cs_ed").value;
		
		if(d == 'sd' && ed == '' ) document.getElementById("cs_ed").value= sd;
		else if(d == 'ed' && sd == '') document.getElementById("cs_sd").value = ed;
		else if(d == 'sed'){
			document.getElementById("cs_ed").value= '';
			document.getElementById("cs_sd").value = '';
			fnSED();
		}
	}
	//리셋
	function fnReset(frm) {
		fnCD('sed');
		$( "#sa_search" ).selectpicker('val','sa_nm');
		$( "#pd_search" ).selectpicker('val','pd_nm');
		$( "#sa_dpm" ).selectpicker('val','0');
		$( "#sa_gd" ).selectpicker('val','0');
		$( "#cs_loan" ).selectpicker('val','0');
		$( "#cs_search" ).selectpicker('val','cs_no');
	}
	
	//검색
	function fnListView(){
		$.ajax({
			url : '${pageContext.request.contextPath}/Coun/CounList.clamp',
			type : 'POST',
			cache : false,
			data : $("#frm").serialize(),
			success: function(html){
				$("#coun_list").html(html);
			}
		});
	}
	
	//페이징
	function fnPaging(page){
		$.ajax({
			url : '${pageContext.request.contextPath}/Coun/CounList.clamp',
			type : 'POST',
			cache : false,
			data : 'listPage='+page+"&full=paging",
			success: function(html){
				$("#coun_list").html(html);
			}
		});
	}
	//글 등록
	function fnWrite(){
		if("${sessionScope.mid}" != "1408M001"){
			location.href= '${pageContext.request.contextPath}/Coun/CounWriteForm.clamp';
		}else{
			alert("관리자님은 상담을 등록 하실수없습니다!");
		}
	}
	
	function fnOver(div) {
		div.style.backgroundColor="#eeeeee";
	}
	
	function fnOut(div) {
		div.style.backgroundColor="#ffffff";
	}
	
</script>
</head>
<body>
	<div id="counsel" align="center">
	<div style="width: 1200px;">
		<h1 style="text-align: center;">상담 목록<small>Counsel List</small></h1>
		<!-- 검색관련 -->
		<div style="margin-top: 25px; margin-bottom: 20px; background-color: #F6F6F6;" align="left">
			<form action="" id="frm" name="frm" method="post" onreset="fnReset(this)">
				<input type="hidden" id="full" name="full" value="full">
				<input type="hidden" id="listPage" name="listPage" value="1">
				<input class="btn input-sm btn-danger" type="button" id="btn1" value="상세 검색(클릭시 상세검색 폼 열림)" onclick="fnFullFind()" style="margin-bottom: 10px;">
				<div id="fullFind">
					<!-- 사원관련 -->
					<div class="find">
						<p style="display: inline-block; width: 29%">
							<select id="sa_search" name="sa_search" class="cl_select input-sm col-lg-3 ">
								<option value="sa_nm">사원명</option>
								<option value="sa_no">사원번호</option>
							</select>
							<input type="text" id="sa_find" name="sa_find" class="form-control input-sm" style="width: auto; display: inline-block;">
						</p>
						<p style="display: inline-block; width: 29%">
							<label class="cl_lbl input-sm label-danger">부서명</label>
							<select id="sa_dpm" name="sa_dpm" class="cl_select input-sm  col-lg-3">
								<option value="0">부서명</option>
								<c:forEach items="${sadps}" var="sadp">
									<option value="${sadp.cd_grp2 }">${sadp.cd_grp2_nm }</option>
								</c:forEach>
							</select>
						</p>
						<p style="display: inline-block; width: 29%">
							<label class="cl_lbl input-sm label-danger">직급명</label>
							<select id="sa_gd" name="sa_gd" class="cl_select input-sm  col-lg-3">
								<option value="0">직급명</option>
								<c:forEach items="${psts}" var="pst">
									<option value="${pst.cd_grp2 }">${pst.cd_grp2_nm }</option>
								</c:forEach>
							</select>
						</p>
					</div>
					<!-- 상품  -->
					<div class="find">
						<p style="display: inline-block; width: 29%">
							<select id="pd_search" name="pd_search" class="cl_select input-sm  col-lg-3">
								<option value="pd_nm">상품명</option>
								<option value="pd_no">상품번호</option>
							</select>
							<input type="text" id="pd_find" name="pd_find" class="form-control input-sm" style="width: auto; display: inline-block;">
						</p>
						<p style="display: inline-block; width: *;">
							<label class="cl_lbl input-sm label-danger" style="width: 100px;margin-right: 10px;">상담 시작일</label>
							<input id="cs_sd" name="cs_sd" type="text" class="form-control input-sm" style="width: auto; 
							display: inline-block;" readonly="readonly" placeholder="검색 시작일" onchange="fnCD('sd')">
							<label>&nbsp;~&nbsp;</label>
							<input id="cs_ed" name="cs_ed" type="text" class="form-control input-sm" style="width: auto; 
								display: inline-block;" readonly="readonly" placeholder="검색 종료일" onchange="fnCD('ed')">
						</p>
					</div>
					<!-- 날짜등 -->
					<div class="find">
					</div>
				</div><!-- 상세검색 끝 -->
				<!-- 상담 -->
				<div class="find">
					<p style="display: inline-block; width: 29%">
						<select id="cs_search" name="cs_search" class="cl_select input-sm  col-lg-3">
							<option value="cs_no">상담번호</option>
							<option value="rg_pp">당담자</option>
						</select>
						<input id="cs_find" name="cs_find" type="text" class="form-control input-sm" style="width: auto; display: inline-block;">
					</p>
					<p style="display: inline-block; width: 29%;">
						<label class="cl_lbl input-sm label-danger">대출액</label>
						<select id="cs_loan" name="cs_loan" class="cl_select2 input-sm  col-lg-3">
							<option value="0">대출액</option>
							<option value="10000">1억원 이하</option>
							<option value="7000">7천만원 미만</option>
							<option value="5000">5천만원 미만</option>
							<option value="3000">3천만원 미만</option>
							<option value="1000">1천만원 미만</option>
						</select>
					</p>
					<p style="display: inline-block; width: 25%;">
						<label class="cl_lbl input-sm label-danger">계약상태</label>
						<select id="ct_ing" name="ct_ing" class="cl_select2 input-sm  col-lg-3">
							<option value="0">계약상태</option>
							<c:forEach items="${ctings }" var="cting" varStatus="loop">
								<option value="${cting.cd_grp2 }">${cting.cd_grp2_nm }</option>
							</c:forEach>
						</select>
					</p>
					<p style="display: inline-block; width: 15%; text-align: right;">
						<input class="btn input-sm btn-primary" type="button" value="검색" style="display: inline-block;" onclick="fnListView()">
						<input class="btn input-sm btn-primary" type="reset" value="초기화" style="display: inline-block;">
					</p>
				</div>
			</form>
		</div>
		<div align="right" style="margin: 15px; margin-right: 0;">
			<input class="btn input-sm btn-primary" type="button" value="상담등록" style="display: inline-block;" onclick="fnWrite()">
		</div>
		<!-- 검색 목록 -->
		<div id="coun_list" style="margin-top: 20px; height: 250px;">
		</div>
	</div>
	</div>
	<form action="" id="view" name="view" method="post">
		<input type="hidden" id="cs_no" name="cs_no">
	</form>
</body>
</html>